package com.bkbw.live.common.fsm;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class GameStateMachineTest {
	
	static class KingkongStateMachine extends GameStateMachine
	{
		enum KingkongState
		{
			state1(0),state2(1),state3(2);
			private int value;
			public int value(){
				return value;
			}
			KingkongState(int value) {
				this.value = value;
			}
		}
		
		GameState st1 = new GameState(KingkongState.state1.value);
		GameState st2 = new GameState(KingkongState.state2.value);
		GameState st3 = new GameState(KingkongState.state3.value);
		
		int count = 0;
		public void init()
		{
			st1.onEnter = () -> {
				System.out.println("enter state1");
			};
			st1.onExit = () -> {
				System.out.println("exit state1");
			};
			st1.onUpdate = (dt) -> {
				count++;
				if (count > 100) {
					setState(st2);
				}
			};
			
			st2.onEnter = () -> {
				System.out.println("enter state2");
			};
			st2.onExit = () -> {
				System.out.println("exit state2");
			};
			st2.onUpdate = (dt) -> {
				count++;
				if (count > 200) {
					setState(st3);
				}
			};
			
			st3.onEnter = () -> {
				System.out.println("enter state3");
			};
			st3.onExit = () -> {
				System.out.println("exit state3");
			};
			st3.onUpdate = (dt) -> {
				count++;
				if (count > 300) {
					count = 0;
					setState(st1);
				}
			};
			
			setState(st1);
		}
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void test() {
		KingkongStateMachine ksm = new KingkongStateMachine();
		ksm.init();
		for (int i = 0; i < 1000; i++) {
			ksm.update(1.0f);
		}
	}

}
